package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Administrator
 * Date: 2023-07-02
 * Time: 20:17
 */
interface IFlying{
    void fly();
}
interface ISwimming{
    void swim();
}
interface IRunning{
    void run();
}

abstract class Animal{
    private String name;
    private int age;
    public Animal(String name,int age){
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public abstract void eat();

}

class Dog extends Animal implements IRunning,ISwimming{

    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(this.getName()+"正在吃狗粮");
    }

    @Override
    public void run() {
        System.out.println(this.getName()+"用四条腿跑");
    }

    @Override
    public void swim() {
        System.out.println(this.getName()+"正在狗刨");
    }
}
class Bird extends Animal implements IFlying{
    public Bird(String name,int age){
        super(name,age);
    }

    @Override
    public void eat() {
        System.out.println(this.getName()+"吃鸟食");
    }

    @Override
    public void fly(){
        System.out.println(this.getName()+"正在用翅膀飞");
    }
}
public class Teest {
    public static void test1(Animal animal){
        animal.eat();
    }
    public static void testFly(IFlying iFlying){
        iFlying.fly();
    }
    public static void testSwim(ISwimming iSwimming){
        iSwimming.swim();
    }
    public static void testRun(IRunning iRunning){
        iRunning.run();
    }
    public static void main(String[] args) {
        test1(new Bird("小鸟",2));
        test1(new Dog("小狗",2));
        testFly(new Bird("小鸟",1));
        testSwim(new Dog("小狗",2));
        testRun(new Dog("小狗",2));
    }
}
